<template>
  <section>
    <el-button
            v-permission="installPermissions.permissions.task.edit"
            @click="handleDetail(row)"
            type="text"
            size="small"
    >
      详情
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.task.send"
      @click="publish(row)"
      type="text"
      size="small"
    >
      派发
    </el-button>
    <el-button
            v-permission="installPermissions.permissions.task.edit"
            @click="handleEdit(row)"
            type="text"
            size="small"
    >
      编辑
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.task.del"
      @click="handleDelete(row)"
      type="text"
      size="small"
    >
      删除
    </el-button>
  </section>
</template>
<style>
</style>
<script>
export default {
  props: {
    row: {
      type: Object,
      default: function() {
        return {};
      }
    },
    col: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  methods: {
    handleStatus() {
      let ops = this.row.status.value == "EFFECTIVED" ? "禁用" : "激活";
      let status =
        this.row.status.value == "EFFECTIVED" ? "INVALID" : "EFFECTIVED";
      this.$confirm("此操作将" + ops + "该用户, 是否继续?", ops + "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$api.user.status(this.row.id, status, () => {
          this.$message({
            type: "success",
            message: ops + "用户成功",
            onClose: this.$emit("deleteDone", this.row)
          });
        });
      });
    },
    handleDelete() {
      this.$confirm("此操作将删除该任务模板, 是否继续?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$api.template.delete(this.row.id, () => {
          this.$message({
            type: "success",
            message: "删除任务模板成功",
            onClose: () => {
              this.$emit("deleteDone", this.row);
            }
          });
        });
      });
    },
      handleReset() {
          this.$confirm("此操作将重置该用户密码, 是否继续?", "重置密码提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
          }).then(() => {
              this.$api.user.reset(this.row.id, () => {
                  this.$message({
                      type: "success",
                      message: "重置密码成功",
                      onClose: () => {
                          this.$emit("deleteDone", this.row);
                      }
                  });
              });
          });
      },
    handleEdit() {
      this.$emit("editRow", this.row);
    },
    publish(){
      this.$emit("publishRow", this.row);
    },
    handleGrant() {
      this.$emit("grantShow", this.row);
    },
    handleDetail(){
      this.$router.push({path: "/template/detail",query:{templateId:this.row.id}})
    }
  }
};
</script>
